import importlib

from defense.base_defense import BaseDefense

def get_defense(name, model_name, config):
    defense = importlib.import_module('defense.methods.' + name).Defense(model_name, config)
    assert isinstance(defense, BaseDefense), 'Defense class must extend defense.base_defense.BaseDefense'
    assert defense.name == name, 'Defense name must be the same as its file name'
    return defense
